/**
 * @file codeforces/1672/d/main
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/5/16 18:04:00
 **/

// TODO: 再看一遍

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = (s); i < (e); ++i)
typedef long long ll;
typedef vector<int> vi;
const int N = 200005;
int t, n, a[N], b[N], cnt[N];
int main() {
  // High rating and good luck!
  cin >> t;
  while (t--) {
    cin >> n;
    rep(i, 1, n + 1) { cnt[i] = 0; }
    rep(i, 0, n) { cin >> a[i]; }
    rep(i, 0, n) { cin >> b[i]; }
    int i = 0, j = 0;
    bool pos = 1;
    while (j < n) {
      if (i < n && j < n && a[i] == b[j]) {
        i++;
        j++;
        continue;
      }
      if (cnt[b[j]] > 0 && b[j] == b[j - 1]) {
        cnt[b[j++]]--;
      } else if (i < n) {
        cnt[a[i++]]++;
      } else {
        pos = 0;
        break;
      }
    }
    if (pos) {
      //      assert(i == n);
      //      rep(i, 1, n + 1) { assert(cnt[i] == 0); }
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
